package coms.action;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import coms.datatransfer.RoleDTO;
import coms.datatransfer.UserDTO;
import coms.ejb.sessionbean.UserBeanRemote;

public class RegistrationAction extends ActionSupport implements ModelDriven<UserDTO> {
	
	
	/**
	 * 
	 */
	
	private static final long serialVersionUID = 1L;
	
	private UserDTO ud=new UserDTO();
	private RoleDTO role = new RoleDTO();

	public String execute()
	{
		
		return "SUCCESS";
		
	}
	
	
	public String submitForm() 
	{
		try{
		
		System.out.println("Submited the form");
		
		//ud.getRoleDTO().setRoleID(1);
		role.getListOfUsers();
		
		
		UserBeanRemote bean = lookupRemoteBean();
		
		bean.createUser(ud);
		
		return "SUBMITTED";
		} catch (Exception e){
			return "exception";
		}
		
	}
	
	
	
	private UserBeanRemote lookupRemoteBean() throws NamingException{
		InitialContext ctx = new InitialContext();
		return (UserBeanRemote) ctx.lookup("java:app/coms-ejb/UserBean!coms.ejb.sessionbean.UserBeanRemote");
	}

	

	@Override
	public UserDTO getModel() {
		// TODO Auto-generated method stub
		return ud;
	}

}
